<%@ page import="java.util.Date" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page language="java" contentType="text/html; charset=windows-31j"
    pageEncoding="windows-31j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>Jsp page</title>
</head>
<body>
<h2>jsp</h2>
<%
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        String schema = "testdb";
        String table = "testtable";
        String[] fields = {"id","title"};
        int length = fields.length;

        try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                String connectionUrl = "jdbc:mysql://localhost:3306/" + schema;
                String connectionUser = "test";
                String connectionPassword = "pw";
                conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
                stmt = conn.createStatement();
                rs = stmt.executeQuery("SELECT * FROM " + table);
                while (rs.next()) {
                        for (int i = 0; i < length; i++) {
                                String field = fields[i];
                                String val = rs.getString(field);
                                out.println("<p>" + field + ": " + val + "<p>");
                        }
                        out.println();
                }
        } catch (Exception e) {
                out.println(e);
                e.printStackTrace();
        } finally {
                try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
                try { if (stmt != null) stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
                try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
        }

%>
</body>
</html>